List = [[30, 4], [10, -1], [20, 0], [15, 1], [21, 3]]
head = 2
q = -1
p = head
list1 = []
while p != -1:
    list1.append(List[p][0])
    # start==翻转链接最重要的四行代码
    tmp = List[p][1]
    List[p][1] = q
    q = p
    p = tmp
    # end==
head = q
print(list1)
print(head, List)

p2 = head
list2 = []
while p2 != -1:
    list2.append(List[p2][0])
    p2 = List[p2][1]
print(list2)
